<?php

declare(strict_types=1);

namespace Modules\Film\Http\Controllers;

use Catch\Base\CatchController as Controller;
use Illuminate\Http\Request;
use Modules\Film\Models\FilmOrder;
use Modules\Member\Models\Members;
use Modules\Member\Models\MembersPriceLog;
use Modules\Member\Models\MembersWithdraw;
use Modules\Order\Models\Orders;

/**
 * 订单控制器
 */
class FilmController extends Controller
{
    public function __construct(
        protected readonly FilmOrder $model
    ) {
    }

    public function index(): mixed
    {
        $this->model->where('is_paid',0)->forceDelete();
        return $this->model->setBeforeGetList(function ($query){
            return $query->with('user')->where('is_paid',1);
        })->getList();
    }

    /**
     * @return mixed
     */
    public function store(Request $request)
    {
        $params = $request->all();
        return $this->model->storeBy($params);
    }

    /**
     * @param $id
     * @return mixed
     */
    public function show($id): mixed
    {
        return $this->model->firstBy($id);
    }

    /**
     * @param $id
     * @param Request $request
     * @return mixed
     */
    public function update($id, Request $request): mixed
    {
        $params = $request->all();
        $info = $this->model->find($id);
        return $this->model->updateBy($id, $request->all());
    }

    /**
     * @param $id
     * @return mixed
     */
    public function destroy($id): mixed
    {
        return $this->model->deleteBy($id);
    }

    /**
     * @param $id
     * @return bool
     */
    public function enable($id)
    {
        return $this->model->toggleBy($id);
    }

}
